<PageHeader as |p|>
  <p.top>
    <KeyValueHeader @baseKey={{baseKey}} @path="vault.cluster.access.leases.list" @model={{clusterController.model.name}} @root={{backendCrumb}} @showCurrent={{true}} />
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      <LinkTo @route="vault.cluster.access.leases.list-root">
        Leases
      </LinkTo>
    </h1>
  </p.levelLeft>
</PageHeader>

<Toolbar>
  <ToolbarFilters>
    <NavigateInput
      @filterFocusDidChange={{action "setFilterFocus"}}
      @filterDidChange={{action "setFilter"}}
      @filter={{this.filter}}
      @filterMatchesKey={{filterMatchesKey}}
      @firstPartialMatch={{firstPartialMatch}}
      @baseKey={{get baseKey "id"}}
      @shouldNavigateTree={{true}}
      @mode="leases"
      @placeholder="Filter leases" />
     {{#if filterFocused}}
       &nbsp;
       &nbsp;
       {{#if filterMatchesKey}}
         {{#unless filterIsFolder}}
           <p class="help has-text-grey is-size-8">
             <kbd>ENTER</kbd> to go to see details
           </p>
         {{/unless}}
       {{/if}}
       {{#if firstPartialMatch}}
         <p class="help has-text-grey is-size-8">
           <kbd>TAB</kbd> to complete
         </p>
       {{/if}}
     {{/if}}
  </ToolbarFilters>
  <ToolbarActions>
    {{#if (not-eq baseKey.id '')}}
      <div class="control">
        {{#if (and capabilities.forceRevokePrefix.canUpdate (not confirmingRevoke))}}
          <ConfirmAction
            @buttonClasses="toolbar-link"
            @confirmTitle="Disable this?"
            @confirmMessage={{concat "All leases under this one will also be removed and disregard any errors encountered."}}
            @confirmButtonText="Revoke"
            @onConfirmAction={{action "revokePrefix" baseKey.id true}}
          >
            Force revoke prefix
          </ConfirmAction>
        {{/if}}
      </div>
      <div class="control">
        {{#if (and capabilities.revokePrefix.canUpdate (not confirmingForceRevoke))}}
          <ConfirmAction
            @buttonClasses="toolbar-link"
            @confirmTitle="Revoke this?"
            @confirmMessage={{concat "All leases under this one will also be removed"}}
            @confirmButtonText="Revoke"
            @onConfirmAction={{action "revokePrefix" baseKey.id}}
            data-test-lease-revoke-prefix="true"
          >
            Revoke prefix
          </ConfirmAction>
        {{/if}}
      </div>
    {{/if}}
  </ToolbarActions>
</Toolbar>

{{#if model.meta.total}}
  {{#each model as |item|}}
    <LinkTo @route={{if item.isFolder "vault.cluster.access.leases.list" "vault.cluster.access.leases.show" }} @model={{item.id}} class="list-item-row" data-test-lease-link={{item.id}}><Icon
      @glyph={{if item.isFolder 'folder-outline' 'file-outline'}}
      class="has-text-grey-light"
    /><span class="has-text-weight-semibold">{{or item.keyWithoutParent item.id}}</span></LinkTo>
  {{else}}
    <EmptyState
      @title="There are no leases matching &quot;{{this.filter}}&quot;"
    />
  {{/each}}
{{else}}
  <EmptyState
    @title={{this.emptyTitle}}
  />
{{/if}}
{{#if (gt model.meta.lastPage 1) }}
  <ListPagination @page={{model.meta.currentPage}} @lastPage={{model.meta.lastPage}} @link={{concat "vault.cluster.access.leases.list" (unless baseKey.id "-root")}} @model={{compact (array (if baseKey.id baseKey.id))}} />
{{/if}}
